package com.hymall.controller.wx;

import com.hymall.bean.MarketOrderGoods;
import com.hymall.bean.bo.CommentBO;
import com.hymall.bean.bo.WXOrderBO;
import com.hymall.bean.common.BasePageInfo;
import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.bean.vo.WXOrderDetailVO;
import com.hymall.bean.vo.WxSubmitVo;
import com.hymall.service.wx.WOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: haiyuny
 * @Date: 2022/7/19 9:33
 * @Description:
 */
@RestController
@RequestMapping("wx/order")
public class WXOrderController {

    @Autowired
    WOrderService worderService;

    /**
     * 评论
     *
     * @param commentBO
     * @return
     */
    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody CommentBO commentBO) {
        worderService.comment(commentBO);
        return BaseRespVo.ok(null);
    }


    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, Short showType) {
        CommonData data = worderService.queryOrderLists(info, showType);
        return BaseRespVo.ok(data);

    }
    /**
     * 逻辑付款
     *
     * @param
     * @return
     */
    @RequestMapping("prepay")
    public BaseRespVo prepay(@RequestBody WXOrderBO bo) {

        worderService.prepay(bo.getOrderId());
        return BaseRespVo.ok(null);
    }




    /**
     * 订单详情
     *
     * @param orderId
     * @return
     */
    @RequestMapping("detail")
    public BaseRespVo detail(String orderId) {

        WXOrderDetailVO od = worderService.getOrderDetail(orderId);
        return BaseRespVo.ok(od);
    }


    /**
     * 订单取消
     *
     * @param orderId
     * @return
     */
    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody WXOrderBO orderId) {
        worderService.cancel(orderId);
        return BaseRespVo.ok(null);
    }
    /**
     * 申请退款
     *
     * @param orderId
     * @return
     */
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody WXOrderBO orderId) {
        worderService.refund(orderId);
        return BaseRespVo.ok(null);
    }

    /**
     * 订单删除
     *
     * @param orderId
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody WXOrderBO orderId) {

        worderService.deleteOrder(orderId);
        return BaseRespVo.ok(null);
    }

    /**
     * 确认收货
     *
     * @param orderId
     * @return
     */
    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody WXOrderBO orderId) {
        worderService.confirm(orderId.getOrderId());
        return BaseRespVo.ok(null);
    }

    /**
     * 获取订单货物
     *
     * @param orderId
     * @return
     */
    @RequestMapping("goods")
    public BaseRespVo goods(String orderId, String goodsId) {
        MarketOrderGoods orderGoods = worderService.goods(orderId, goodsId);
        return BaseRespVo.ok(orderGoods);
    }


    @Autowired
    WOrderService wOrderService;

    @PostMapping("submit")
    public BaseRespVo submitOrder(@RequestBody Map<String,Object> map){
        Integer addressId = (Integer) map.get("addressId");
        Integer cartId = (Integer) map.get("cartId");
        Integer couponId = (Integer) map.get("couponId");
        Integer grouponLinkId = (Integer) map.get("grouponLinkId");
        Integer grouponRulesId = (Integer) map.get("grouponRulesId");

        String message = (String) map.get("message");

        Integer orderId = wOrderService.orderSubmit(addressId,cartId,couponId,grouponLinkId,grouponRulesId,message);

        WxSubmitVo data = new WxSubmitVo();
        data.setOrderId(orderId);
        return BaseRespVo.ok(data);
    }
}
